﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;

public partial class SendMail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        using (var msg = new MailMessage()) {
            msg.From = new MailAddress("sender@example.com");
            msg.To.Add("receiver@example.com");
            msg.Subject = "Test message subject";
            msg.Body = "Test message body";

            using (var mx = new SmtpClient()) {
                //mx.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
                //mx.PickupDirectoryLocation = @"C:\InetPub\MailRoot\Pickup";
                mx.Send(msg);
                // or call mx.Dispose(); here instead of the 'using' block
            }
        }
    }
}